﻿3099.哈沙德数
int sumOfTheDigitsOfHarshadNumber(int x) {
    int ans = 0, ret = x;
    while (ret)
    {
        ans += ret % 10;
        ret /= 10;
    }
    if (x % ans == 0)
    {
        return ans;
    }
    return -1;
}

485.最大连续1的个数
int findMaxConsecutiveOnes(int* nums, int numsSize) {
    int l = 0, r = 0, ans = 0, count = 0;
    for (int i = 0; i < numsSize; i++)
    {
        if (nums[i] == 1)
        {
            count++;
            if (count > ans)
            {
                ans = count;
            }
        }
        else
        {
            count = 0;
        }
    }
    return ans;
}

492.构造矩形
/**
 * Note: The returned array must be malloced, assume caller calls free().
 */
int* constructRectangle(int area, int* returnSize) {
    int* ans = (int*)malloc(sizeof(int) * 2);
    int L = 0, M = 0, dval = 10000000;

    for (int i = 1; i <= sqrt(area); i++)
    {
        if (area % i == 0)
        {

            if (abs(area / i - i) < dval)
            {
                L = area / i;
                M = i;
                dval = abs(L - M);
            }
        }
    }
    ans[0] = L;
    ans[1] = M;
    *returnSize = 2;

    return ans;
}

495.提莫攻击
int findPoisonedDuration(int* timeSeries, int timeSeriesSize, int duration) {
    int ans = 0, temp = -1;
    for (int i = 0; i < timeSeriesSize; i++)
    {
        if (timeSeries[i] < temp)
        {
            ans += timeSeries[i] - timeSeries[i - 1];
        }
        else
        {
            ans += duration;
        }
        temp = timeSeries[i] + duration;
    }

    return ans;
}

